﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace DataConvertLib
{
	/// <summary>
	/// Float类型数据转换类
	/// </summary>
	// Token: 0x0200000A RID: 10
	[Description("Float类型数据转换类")]
	public class FloatLib
	{
		/// <summary>
		/// 将字节数组中某4个字节转换成Float类型
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="start">开始索引</param>
		/// <param name="dataFormat">数据格式</param>
		/// <returns>返回一个浮点数</returns>
		// Token: 0x06000050 RID: 80 RVA: 0x00003BA8 File Offset: 0x00001DA8
		[Description("将字节数组中某4个字节转换成Float类型")]
		public static float GetFloatFromByteArray(byte[] value, int start = 0, DataFormat dataFormat = DataFormat.ABCD)
		{
			byte[] value2 = ByteArrayLib.Get4BytesFromByteArray(value, start, dataFormat);
			return BitConverter.ToSingle(value2, 0);
		}

		/// <summary>
		/// 将字节数组转换成Float数组
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="dataFormat">数据格式</param>
		/// <returns>返回浮点数组</returns>
		// Token: 0x06000051 RID: 81 RVA: 0x00003BCC File Offset: 0x00001DCC
		[Description("将字节数组转换成Float数组")]
		public static float[] GetFloatArrayFromByteArray(byte[] value, DataFormat dataFormat = DataFormat.ABCD)
		{
			bool flag = value == null;
			if (flag)
			{
				throw new ArgumentNullException("检查数组长度是否为空");
			}
			bool flag2 = value.Length % 4 != 0;
			if (flag2)
			{
				throw new ArgumentNullException("检查数组长度是否为4的倍数");
			}
			float[] array = new float[value.Length / 4];
			for (int i = 0; i < value.Length / 4; i++)
			{
				array[i] = FloatLib.GetFloatFromByteArray(value, 4 * i, dataFormat);
			}
			return array;
		}

		/// <summary>
		/// 将Float字符串转换成单精度浮点型数组
		/// </summary>
		/// <param name="value">Float字符串</param>
		/// <param name="spilt">分隔符</param>
		/// <returns>单精度浮点型数组</returns>
		// Token: 0x06000052 RID: 82 RVA: 0x00003C3C File Offset: 0x00001E3C
		[Description("将Float字符串转换成单精度浮点型数组")]
		public static float[] GetFloatArrayFromString(string value, string spilt = " ")
		{
			value = value.Trim();
			List<float> list = new List<float>();
			float[] result;
			try
			{
				bool flag = value.Contains(spilt);
				if (flag)
				{
					string[] array = value.Split(new string[]
					{
						spilt
					}, StringSplitOptions.RemoveEmptyEntries);
					foreach (string text in array)
					{
						list.Add(Convert.ToSingle(text.Trim()));
					}
				}
				else
				{
					list.Add(Convert.ToSingle(value.Trim()));
				}
				result = list.ToArray();
			}
			catch (Exception ex)
			{
				throw new ArgumentNullException("数据转换失败：" + ex.Message);
			}
			return result;
		}
	}
}
